package svc.elib.analysis;

import java.io.IOException;
import java.util.LinkedList;

import svc.elib.db.Author;
import svc.elib.db.Database;
import svc.elib.socnet.CentralityMetrics;
import svc.elib.socnet.EvolutionarySnapshots;
import svc.elib.socnet.Net;
import svc.elib.socnet.SocConstructor;

public class EvolutionHighestRankAuthor {

	private Net[] snaps;
	private int startYear;
	
	public EvolutionHighestRankAuthor(Net net) {
		EvolutionarySnapshots es = new EvolutionarySnapshots(net);
		startYear = es.getStartYear();
		snaps = es.getSnapshots();
	}
	
	public void analysis() {
		for (int i = 0; i < snaps.length; i++) {
			Net cSnap = snaps[i];
			int year = startYear + i;
			
			if (year == 1932 || year == 2011 || year % 5 == 0) {
				System.out.print(year + " & ");
			
				LinkedList<Author> maxPapers = cSnap.getAuthorWithMaxPapers(year);
				if (maxPapers.size() == 1) {
					System.out.print(maxPapers.get(0).getName() + " & " + Net.__numPapers);
				} else {
					System.out.print(maxPapers.size() + " authors & " + Net.__numPapers);
				}
			
		
				LinkedList<Author> maxDegree = cSnap.getHighestDegreeAuthor();
				if (maxDegree.size() == 1)
					System.out.print(" & " + maxDegree.get(0).getName() + " & " + Net.__maxDeg);
				else
					System.out.print(" & " + maxDegree.size() + " authors & " + Net.__maxDeg);
				
			
				Author maxBet = cSnap.getAuthorWithMaxBet();
				if (Net.__maxBet == 0)
					System.out.print(" & - & " + Net.__maxBet);
				else
					System.out.print(" & " + maxBet.getName() + " & " + Net.__maxBet);
				
				System.out.println(" \\\\ ");
			}
		}
	}
	
	public static void main(String[] args) 
		throws IOException
	{
		Database db = new Database("eLibData.csv", 1932, 2011);
		SocConstructor soc = new SocConstructor(db);
		Net net = soc.getNet();
		
		EvolutionHighestRankAuthor e = new EvolutionHighestRankAuthor(net);
		e.analysis();
	}
	
}
